<?
class Navi{
    private $leftNaviArray=array();
    private $leftNaviArrayT=array();
    private $dtype;
    public function __construct($leftArray,$leftNaviArrayT,$dtype){
        $this->dtype = $dtype;
        $this->leftNaviArrayT=$leftNaviArrayT;
        foreach($leftArray as $row){
            if(!in_array($dtype,explode(",",$row['limit']))) continue;
            $this->leftNaviArray[]=$row;
        }

    }
    public function output(){
        $out_array=array();
        foreach($this->leftNaviArray as $row){
            $out_array[$row['part']][]=$row;
        }
        ?>
        <dl class="membdl">
            <?foreach($out_array as $k=>$items){?>
                <dt><?=$this->leftNaviArrayT[$k]?></dt>
                <?foreach($items as $row){?>
                    <dd><a href="<?=$row['url']?>" target="<?=$row['target']?>"><?=$row['title']?></a></dd>
                <?}?>
            <?}?>
        </dl>
    <?
    }
    /*
	public function breadcrumb(){
		$url=basename($_SERVER['PHP_SELF']);//.($_SERVER["QUERY_STRING"]?"?".$_SERVER["QUERY_STRING"]:"")
		foreach($this->leftNaviArray as $row){
			if($row['url']==$url){
				$title=$row['title'];
				$url=$row['url'];
			}
		}
		if($title){?>
		您所在位置： <a href="home.html">首页</a><em>&gt;</em><a href="#">系统管理</a><em>&gt;</em><a href="<?=$url?>"><?=$title?></a>
		<?}
	}
    */
    /**
     * @param $pages
     * @param $depth
     * @return string
     */
    function breadcrumb($pages, $depth) {
        $currentPage = basename($_SERVER['PHP_SELF']);
        $parent = $pages[$currentPage]['parent'];
        if($currentPage!='home.html') {
            if(is_numeric($parent)) {
                $dep = $parent;
                $nav = '<em>&gt;</em><span>'.$depth[$dep].'</span>'
                    .'<em>&gt;</em>'
                    .'<a href="javascript:;">'.$pages[$currentPage]['pageTitle'].'</a>';
            }
            else {
                $dep = $pages[$parent]['parent'];
                $nav = '<em>&gt;</em><span>'.$depth[$dep].'</span>'
                    .'<em>&gt;</em><a href="'.$parent.'">'
                    .$pages[$parent]['pageTitle'].'</a>'
                    .'<em>&gt;</em><a href="javascript:;">'
                    .$pages[$currentPage]['pageTitle'].'</a>';

            }
        }
        $url = "http://{$_SERVER['HTTP_HOST']}/home.html";
		if(strpos($_SERVER['SCRIPT_URL'], '/new/d')!==false) $url = "http://{$_SERVER['HTTP_HOST']}/new/d/home.html";
        $sub_nav = '<div class="subnav">您所在位置： <a href="'.$url.'">首页</a>'.$nav.'</div>';
        return $sub_nav;
    }
}
?>